package com.tingyukeji.fastpay.login.utils;

import android.os.CountDownTimer;
import android.widget.Button;

/**
 * Created by Administrator on 2016/11/18.
 */

public class UserCountTimer extends CountDownTimer implements TimerCallBack {
    private Button btnCode;
    private String str1;
    private String str2;
    private boolean payTimer = false;

    public UserCountTimer(long millisInFuture, long countDownInterval, Button btnCode, String str1, String str2) {
        super(millisInFuture, countDownInterval);
        this.btnCode = btnCode;
        this.str1 = str1;
        this.str2 = str2;
    }

    public UserCountTimer(long millisInFuture, long countDownInterval, Button btnCode, String str1, String str2, boolean payTimer) {
        super(millisInFuture, countDownInterval);
        this.btnCode = btnCode;
        this.str1 = str1;
        this.str2 = str2;
        this.payTimer = payTimer;
    }

    public UserCountTimer(long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);
    }

    @Override
    public void onTick(long millisUntilFinished) {
        btnCode.setText((millisUntilFinished / 1000) + str1);
        if (!payTimer){
//            btnCode.setBackgroundResource(R.drawable.border_solid_gray);
        }
    }

    @Override
    public void onFinish() {
        if (!payTimer){
//            btnCode.setBackgroundResource(R.drawable.border_solid_blue);
        }
        btnCode.setEnabled(true);
        btnCode.setText(str2);
        timerCallBackListener.onFinish();
    }

    private TimerCallBackListener timerCallBackListener;

    @Override
    public void setTimerCallBackListener(TimerCallBackListener timerCallBackListener) {
        this.timerCallBackListener = timerCallBackListener;
    }
}
